package com.gwz.sys.utils;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.gwz.sys.domain.User;

/**
 * web对象的工具类
 * @author LJH
 *
 */
public class WebUtils {

	/**
	 * 得到当前线程的requst
	 */
	public static HttpServletRequest getCurrentRequest(){
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) 
				RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = requestAttributes.getRequest();
		return request;
	}

	/**
	 * 得到当前线程的response
	 */
	public static HttpServletResponse getCurrentResponse(){
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) 
				RequestContextHolder.getRequestAttributes();
		return requestAttributes.getResponse();
	}

	/**
	 * 得到当前线程的session
	 */
	public static HttpSession getCurrentSession(){
		return getCurrentRequest().getSession();
	}
	/**
	 * 得到当前线程的servletContext
	 */
	public static ServletContext getServletContext(){
		return getCurrentRequest().getServletContext();
	}
	
	/**
	 * 得到当前登陆的对象
	 */
	public static User getCurrentUser(){
		User user=(User) getCurrentSession().getAttribute("user");
		return user;
	}
	
	
}
